if(pos('/',url)>0) then do;host=substr(url,1,pos('/',url)-1);path=substr(url,pos('/',url));end
else do;host=url;path='/';end
if(pos(':',host)>0) then do;port=substr(host,pos(':',host)+1);host=substr(host,1,pos(':',host)-1);end
if ~GetHost('HOST',host) then;if(datatype(compress(host,'.'),'N')) then do;host.HOSTADDRLIST.0=host;lookup=0;end;else do;say 'Unable to lookup host!!!';iterate x;end
sock=Socket('INET','STREAM','IP');if sock<0 then do;say 'Unable to create socket!!!';iterate x;end
if(pos('/',url)>0) then do;host=substr(url,1,pos('/',url)-1);path=substr(url,pos('/',url));end
else do;host=url;path='/';end
if(pos(':',host)>0) then do;port=substr(host,pos(':',host)+1);host=substr(host,1,pos(':',host)-1);end
if(savepath~='') then
do
if(right(savepath,1)~=':' & right(savepath,1)~='/') then savepath=savepath'/'
if(path='/') then filename=mp3tmp'.mp3'
else filename=substr(path,lastpos('/',path)+1)
end
crlf=d2c(13)''d2c(10);lookup=1
if ~GetHost('HOST',host) then;if(datatype(compress(host,'.'),'N')) then do;host.HOSTADDRLIST.0=host;lookup=0;end;else do;setclip(mp3tmp,'Unable to lookup host!!!');return 10;end
sock=Socket('INET','STREAM','IP');if sock<0 then do;setclip(mp3tmp,'Unable to create socket!!!');return 10;end
if Connect(sock,'CONN')<0 then do;if(lookup) then setclip(mp3tmp,'Sorry, server is down, unable to stream data!');else setclip(mp3tmp,'Host does not exist!!!');return 10;end
req='GET 'path' HTTP/1.0'crlf''crlf
call Send(sock,req)
call open(pipe,'PIPE:'mp3tmp,W)
if(save) then do;call open(file,savepath''filename,W);num=1;end
len=1;start=0
do y=1 while len>0
if(start) then
do
len=recv(sock,'BUF',bfsize);bfsize=pbsize
if(len>0) then
do
call writech(pipe,buf)
if(save) then call writech(file,buf)
end
clip=getclip(mp3tmp)
if(clip='DIE') then do;setclip(mp3tmp);return 0;end
if(clip='SAVE' & save=0) then do;save=1;num=num+1;if(num>1) then app='.'num;call open(file,savepath''filename''app,W);call writech(file,buf);end
if(clip='NOSAVE' & save=1) then do;save=0;call close(file);if(comment) then if(shoutcast & name~=host & name~='') then address command 'FileNote "'savepath''filename''app'" "'name'"';else address command 'FileNote "'savepath''filename''app'" http://'url;end
end
else
do
len=recvline(sock,'BUF',1024)
if(y=1 & word(buf,1)='ICY') then shoutcast=1
if(y=1 & word(buf,2)~='200') then do;setclip(mp3tmp,strip(subword(buf,3),'T',crlf));return 10;end
if(word(buf,1)='Content-Length:') then size=strip(word(buf,2),'T',crlf)
if(left(buf,9)='icy-name:') then name=compress(strip(substr(buf,10),'T',crlf),"'""")
if(left(buf,10)='icy-genre:') then genre=compress(strip(substr(buf,11),'T',crlf),"'""")
if(left(buf,7)='icy-br:') then bitr=strip(substr(buf,8),'T',crlf)
if(buf=crlf) then do;start=1;setclip(mp3tmp,'PLAY');call OpenReq();end
end
end
return 0
OpenReq:
if(reqtools) then
do
lf=d2c(10)
stbt="'Start _Save'"
spbt="'Stop _Save'"
flsv="'"savepath""filename"'"
if(size='') then size='Unknown'
else size=size' bytes'
if(save=0) then do;svfl="'No'";svbt=stbt;prbt=spbt;end
else do;svfl=flsv;svbt=spbt;prbt=stbt;end
if(name='') then name=host
if(genre='') then genre='Unknown'
if(bitr='') then bitr='Unknown'
else bitr=bitr'kbps'
if(pubscreen='') then reqtags="'rtez_flags=ezreqf_noreturnkey'"